package com.ibs.hadoop.spring.hbase;

import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.client.Result;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.data.hadoop.hbase.HbaseTemplate;
import org.springframework.data.hadoop.hbase.RowMapper;

public class SpringBbaseContext {

    @SuppressWarnings("resource")
    public static void main(String[] args) {

        ApplicationContext context = new ClassPathXmlApplicationContext(
                new String[] { "/spring_hadoop/Spring-hbase.xml" });
        BeanFactory factory = (BeanFactory) context;

        HbaseTemplate htemplate = (HbaseTemplate) factory.getBean("htemplate");

        htemplate.get("LTE_DNS_QUERY_20160829", "00000357200006420160508080449000108", new RowMapper<String>() {

            @Override
            public String mapRow(Result result, int rowNum) throws Exception {
                // TODO Auto-generated methodstub
                Cell cell = result.listCells().get(0);

                System.out.println(cell);

                String family = new String(CellUtil.cloneFamily(cell));
                String qualifier = new String(CellUtil.cloneQualifier(cell));
                String value = new String(CellUtil.cloneValue(cell));
                String rowId = new String(CellUtil.cloneRow(cell));

                System.out.print("row:" + rowId + ",");
                System.out.print("family:" + family + ",");
                System.out.print("qualifier:" + qualifier + ",");
                System.out.print("value:" + value + "��");
                System.out.println();

                return null;
            }
        });

    }

}
